#include <iostream>
#include <string>
#include <fstream>
#include "bundle.h"

int main(int argc, char* argv[])
{
    if(argc != 3)
    {
        std::cout << "argv[1]是压缩包名称" << std::endl;
        std::cout << "argv[2]是解压后文件名称" << std::endl;
        return -1;
    }
    std::string ifilename = argv[1];
    std::string ofilename = argv[2];

    //1.把压缩包文件内容读出来
    std::ifstream ifs;
    ifs.open(ifilename, std::ios::binary);
    std::string body;
    ifs.seekg(0, std::ios::end);
    size_t fsize = ifs.tellg();
    ifs.seekg(0, std::ios::beg);
    body.resize(fsize);
    ifs.read(&body[0], fsize);
    ifs.close();

    //2.解压缩
    std::string unpack = bundle::unpack(body);
    std::ofstream ofs;
    ofs.open(ofilename, std::ios::binary);
    ofs.write(&unpack[0], unpack.size());
    ofs.close();
    return 0;
}